package com.xmut.controller;

import com.xmut.mapper.PurchaseRecordMapper;
import com.xmut.pojo.PurchaseRecord;
import com.xmut.pojo.Result;
import com.xmut.service.PurchaseRecordService;
import com.xmut.service.impl.PurchaseRecordServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@CrossOrigin("*")
@RestController

public class PurchaseRecordController {
    @Autowired
    PurchaseRecordService purchaseRecordService;
    @PostMapping("/checkOut")
    public Result checkOut(@RequestBody PurchaseRecord record){

            purchaseRecordService.InsertPurchaseRecord(record);
            System.out.println(record);

        return Result.success(record);
    }
    @GetMapping("/getRecordById/{userId}")
    public Result getRecordById(@PathVariable Integer userId){
        List<PurchaseRecord> purchaseRecordList=purchaseRecordService.getAllRecordById(userId);
        return Result.success(purchaseRecordList);

    }
    @GetMapping("/delRecordById/{id}")
    public Result delRecordById(@PathVariable Integer id){

            purchaseRecordService.delRecordById(id);
            System.out.println( Result.success("deleted"));
            return Result.success("deleted");
    }
    @PostMapping("/payNow")
    public Result payNow(@RequestBody PurchaseRecord record){
            purchaseRecordService.InsertPurchaseRecord(record);
            System.out.println(record);
            return Result.success(record);
    }

    @GetMapping("/getAllRecord")
    public Result getAllRecord()
    {
        List<PurchaseRecord> purchaseRecords = purchaseRecordService.getAllRecord();
        return Result.success(purchaseRecords);
    }


}
